#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main()
{
    struct timespec time_start = { 0, 0 }, time_end = { 0, 0 };
    clock_gettime(CLOCK_MONOTONIC, &time_start); // 获取当前时间
    for(int i=0; i<100; i++);
    clock_gettime(CLOCK_MONOTONIC, &time_end); // 上一条打印语句执行之后，获取当前时间

    printf("start time %llus, %lluns\n", time_start.tv_sec, time_start.tv_nsec);
    printf("end time %llus, %lluns\n", time_end.tv_sec, time_end.tv_nsec);

    // 计算出一条打印语句的运行时间
    printf("duration: %llus %lluns\n", time_end.tv_sec - time_start.tv_sec, time_end.tv_nsec - time_start.tv_nsec);
    return 0;
}
